package com.zoe.wan.android.example.fragment.personal

import android.content.Intent
import com.blankj.utilcode.util.SPUtils
import com.zoe.wan.android.example.BR
import com.zoe.wan.android.example.Constants
import com.zoe.wan.android.example.Constants.SP_USER_NAME
import com.zoe.wan.android.example.R
import com.zoe.wan.android.example.activity.login.LoginActivity
import com.zoe.wan.android.example.databinding.FragmentHomeBinding
import com.zoe.wan.android.example.databinding.FragmentPersonalBinding
import com.zoe.wan.android.example.fragment.home.FragHomeViewModel
import com.zoe.wan.base.BaseFragment

class FragPersonal : BaseFragment<FragmentPersonalBinding, FragPersonalViewModel>() {
    override fun getLayoutId(): Int {
        return R.layout.fragment_personal
    }

    override fun getViewModelId(): Int {
        return BR.personalVm
    }

    override fun initViewData() {


        binding?.personImg?.setOnClickListener {
            shouldLogin()
        }
        binding?.tvUsername?.setOnClickListener {
            shouldLogin()
        }

        binding?.logout?.setOnClickListener{

            viewModel?.logout()
        }

    }

    fun shouldLogin() {
        if (viewModel?.showLogBtn?.get() == true) {
            return
        }
        val userName = SPUtils.getInstance().getString(SP_USER_NAME)


        if (userName.isNullOrEmpty()) {

            val intent = Intent(context, LoginActivity::class.java)
            intent.putExtra(LoginActivity.Intent_type_name, 0)
            startActivity(intent)
        }
    }
}

